﻿/**********************************************************
*
* 模块名称：继承基类,Access特殊专用类,建议仅将复杂操作放入这里实现
* 当前版本：1.0
* 添加人员：楚涛
* 开始时间：2010-10-10
* 版本历史：v1.0
*
***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Database;
using System.Database.Access;

namespace LXChuTao.ECG.Demo.BLL.SimpleFactory
{
    public partial class SubClass1:BaseClass
    {
        public override string Method1()
        {
            return "SubClass1.Method1";
        }

        /// <summary>
        /// Access查询示例方法
        /// </summary>
        /// <returns>查询数据结果集</returns>
        public override DataSet GetDataSet()
        {
            DbCore dbCore = null;
            try
            {
                dbCore = GetDbCore;
                string strSql = "SELECT T_DEMO.C_ID,T_DEMO.C_NAME,T_DEMO.C_IDCARD,T_DEMO.C_DATE,T_DEMO.C_EMAIL,T_DEMO.C_STRING,T_DEMO.C_INT,T_DEMO.C_FLOAT,T_DEMO.C_EIDTDATE FROM T_DEMO";
                DBCommandWrapper cmd = dbCore.GetSqlStringCommandWrapper(strSql);
                //cmd.AddInParameter(
                return dbCore.ExecuteDataSet(cmd);
            }
            catch (Exception ex)
            {
                if (dbCore != null)
                {
                    dbCore.Close();
                }
                throw ex;
            }
        }
        /// <summary>
        /// Access数据库DML操作示例方法
        /// </summary>
        /// <returns>DML操作影响的行数</returns>
        public override int Save()
        {
            DbCore dbCore = null;
            try
            {
                dbCore = GetDbCore;
                dbCore.Open();
                dbCore.BeginTransaction();
                int count;
                string strId = GetKeyId;
                string strSql = "INSERT INTO T_DEMO (C_ID,C_NAME,C_IDCARD,C_EIDTDATE ) VALUES (?,?,?,?)";
                AccessCommandWrapper cmd = dbCore.GetSqlStringCommandWrapper(strSql) as AccessCommandWrapper;
                cmd.AddInParameter("C_ID", DbType.AnsiString, strId);
                cmd.AddInParameter("C_NAME", DbType.AnsiString, "NameInsert");
                cmd.AddInParameter("C_IDCARD", DbType.AnsiString, "340221196606066066");
                cmd.AddInParameter("C_EIDTDATE", DbType.DateTime, DateTime.Now);
                count = dbCore.ExecuteNonQuery(cmd);

                strSql = "UPDATE T_DEMO SET C_NAME=?,C_DATE=?,C_EIDTDATE=? WHERE T_DEMO.C_ID=?";
                cmd = dbCore.GetSqlStringCommandWrapper(strSql) as AccessCommandWrapper;
                cmd.AddInParameter("C_NAME", DbType.AnsiString, "NameIUpdate");
                cmd.AddInParameter("C_DATE", DbType.Date, DateTime.Today);
                cmd.AddInParameter("C_EIDTDATE", DbType.DateTime, DateTime.Now);
                cmd.AddInParameter("C_ID", DbType.AnsiString, strId);
                count += dbCore.ExecuteNonQuery(cmd);

                strSql = "DELETE FROM T_DEMO WHERE T_DEMO.C_EIDTDATE > ?";
                cmd = dbCore.GetSqlStringCommandWrapper(strSql) as AccessCommandWrapper;
                cmd.AddInParameter("C_EIDTDATE", DbType.DateTime, DateTime.Now);
                count += dbCore.ExecuteNonQuery(cmd);

                dbCore.CommitTransaction();
                dbCore.Close();
                return count;
            }
            catch (Exception ex)
            {
                if (dbCore != null)
                {
                    if (dbCore.IsTransaction) dbCore.RollbackTransaction();
                    dbCore.Close();
                }
                throw ex;
            }
        }
    }
}
